package tasks
import java.io.File
import org.stjs.generator
import org.stjs.generator.STJSTranspiler
import java.net.URLClassLoader

object ProjectTranspiler {

  def apply {

    val cl = Thread.currentThread.getContextClassLoader;

    val folder = new File("public");
    def recursive(file: File): Array[File] = {
      val these = file.listFiles;
      these ++ these.filter(_.isDirectory).flatMap(recursive)
    }
    val files = recursive(folder).filter(_.getName.endsWith(".ep.js"));
    files foreach { f =>
      STJSTranspiler.generateFrom(f, cl);
    }

  }

  def main(args: Array[String]) {
    ProjectTranspiler.apply
  }

}